package com.xinruke.hostels.reservation.user.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.EConditionOperator;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.reservation.user.interfaces.dto.UserDetailQueryDto;
import com.xinruke.hostels.reservation.user.interfaces.dto.UserInfoQueryDTO;
import com.xinruke.hostels.reservation.user.interfaces.dto.UserInfoQueryResultDTO;
import com.xinruke.hostels.reservation.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName UserInfoController
 * @CreateDate 2019/6/9
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 用户信息
 */
@RestController
@RequestMapping("user/info")
@Api(tags = "用户信息")
public class UserInfoController extends BaseController {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    UserInfoService userInfoService;

    @PostMapping(value = "userInfoList")
    @ApiOperation(value = "查询用户列表")
    public ResultVO<RowsDataVO<UserInfoQueryResultDTO>> getUserInfoList(@RequestBody UserInfoQueryDTO userInfoQueryDTO) {
        ResultVO resultVO = ResultVO.fail();

        try {
            userInfoQueryDTO.getQueryConditions().addCondition("xingming", EConditionOperator.EQULS, userInfoQueryDTO.getXingming());

            RowsDataVO<UserInfoQueryResultDTO> rowsDataVO = userInfoService.getUserInfoList(userInfoQueryDTO);

            resultVO.setCode(ResultVO.SUCCESS);
            resultVO.setMessage("查询成功");
            resultVO.setData(rowsDataVO);
        } catch (Exception e) {
            logger.error("系统异常", e);
        }

        return resultVO;
    }

    @PostMapping(value = "userDetail")
    @ApiOperation(value = "查询用户列表")
    public ResultVO<UserInfoQueryResultDTO> getUserDetail(@Valid @RequestBody UserDetailQueryDto userInfoQueryDTO) {
        ResultVO resultVO = ResultVO.fail();

        try {
            UserInfoQueryResultDTO rowsDataVO = userInfoService.getUserDetail(userInfoQueryDTO);
            resultVO.setCode(ResultVO.SUCCESS);
            resultVO.setMessage("查询成功");
            resultVO.setData(rowsDataVO);
        } catch (Exception e) {
            logger.error("系统异常", e);
        }

        return resultVO;
    }
}
